// 热销单品
import 'package:flutter/material.dart';
import 'package:smartidea_shop/router/routes.dart';

class HotGoods extends StatefulWidget {
  HotGoods({Key? key}) : super(key: key);

  @override
  HotGoodsState createState() => HotGoodsState();
}

class HotGoodsState extends State<HotGoods> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
          width: 335,
          margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
          child: Column(
            children: [
              // 标题
              Center(
                child: Container(
                  alignment: Alignment.centerLeft,
                  height: 44,
                  child: const Text(
                    '热销商品',
                    style: TextStyle(fontSize: 18),
                  ),
                ),
              ),
              // 商品列表
              Container(
                  color: Colors.white,
                  width: double.infinity,
                  child: HotGoodsItmes())
            ],
          )),
    );
  }
}

class HotGoodsItmes extends StatelessWidget {
/*一个渐变颜色的正方形集合*/
  List<Widget> Boxs(context) => List.generate(10, (index) {
        return InkWell(
          onTap: () {
            String url = Uri.encodeComponent(
                "http://118.190.144.187/u-pages/smart-shop/shop-details");
            ShopRouter.navigateTo(context, "/webview?url=$url");
          },
          child: Column(
            children: [
              Image.network(
                'http://118.190.144.187/u-pages/static/images/ecd463.png',
                fit: BoxFit.cover,
                width: 163,
                height: 163,
              ),
              Container(
                width: 163,
                height: 102,
                child: Column(
                  children: [
                    const Text('夹克外套白色 苏武口联名设计优秀奖系苏...'),
                    // Stack(
                    //   children: <Widget>[
                    //     Positioned(
                    //         //方法二
                    //         left: 15.0,
                    //         bottom: 15.0,
                    //         child: Text(
                    //           '¥329.00',
                    //           style: TextStyle(fontSize: 16, color: Colors.black),
                    //         )),
                    //     Positioned(
                    //         //方法二
                    //         right: 15.0,
                    //         bottom: 15.0,
                    //         child: Text(
                    //           '43件已售',
                    //           style: TextStyle(
                    //             fontSize: 10,
                    //             color: Color.fromRGBO(0, 0, 0, 0.4),
                    //           ),
                    //         )),
                    //   ],
                    // ),
                  ],
                ),
              )
            ],
          ),
        );
      });

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Wrap(
      spacing: 9, //主轴上子控件的间距
      runSpacing: 9, //交叉轴上子控件之间的间距
      children: Boxs(context), //要显示的子控件集合
    ));
  }
}
